﻿function removeGems(matrix) {
    var len = matrix.Length;
    for (var i = 0; i < len; i++) {
        for (var j = 0; j < len; j++) {
            if (matrix[i][j].toRemove) {
                var pos = new Point(i, j);
                moveUpperObjects(matrix, pos);
            }
        }
    }
}

function moveUpperObjects(matrix, point) {
    var row = point.Row;
    var col = point.Col;

    for (var i = row; i > 0; i--) {
        var firstGemPos = new Point(i,col);
        var secondGemPos = new Point(i-1,col);
        swap(matrix, firstGemPos, secondGemPos);
    }

    matrix[0][col] = undefined;
}

function fillEmptyCells(matrix) {
    var len = matrix.Length;
    for (var i = 0; i < len; i++) {
        for (var j = 0; j < len; j++) {
            if (matrix[i][j]) {
                //Generate a gem for this
            }
        }
    }
}



function swap(matrix, firstGemPosition, secondGemPosition ) {
    var oldGem = matrix[secondGemPosition.Row][secondGemPosition.Col];
    matrix[secondGemPosition.Row][secondGemPosition.Col] = matrix[firstGemPosition.Row][firstGemPosition.Col];
    matrix[firstGemPosition.Row][firstGemPosition.Col] = oldGem;
}
